package com.lanqiao.service.impl;

import com.lanqiao.dao.BookDao;
import com.lanqiao.dao.impl.BookImpl;
import com.lanqiao.entity.BookInfo;
import com.lanqiao.entity.BookPicInfo;
import com.lanqiao.service.BookService;

import java.util.List;

public class BookSerImpl implements BookService {
    private BookDao book = new BookImpl();

    @Override
    public boolean addBook(BookInfo bookInfo, List<String> pic_names) {
        //返回插入图的自增长id
        int bookid = book.insertBook(bookInfo);
        if (pic_names.size()>0){
            //循环插入小图
            for(String picname : pic_names){
                //把集合中的图书id和图片名称赋给小图的实体类
                BookPicInfo bookPicInfo = new BookPicInfo();
                bookPicInfo.setBook_id(bookid);
                bookPicInfo.setPic_name(picname);
                //调用插入小图sql，返回影响sql的行数
                int row = book.insertBookPic(bookPicInfo);


            }
        }

        return bookid > 0;
    }

    @Override
    public List<BookInfo> selectBook() {
        return book.selectBook();
    }
}
